<?php
namespace app\admin\controller;

use app\common\controller\AdminBase;
use app\common\model\User as UserModel;

/**
 * 用户管理
 * @package app\admin\controller
 */
class User extends AdminBase
{
    private $model=null;
    public function _initialize()
    {
        if (is_null($this->model)) {
            $this->model = new UserModel;
        }
    }
    // 用户列表
    public function index()
    {
        $data=$this->model->getAllData();
        $this->assign('data', $data);
        return $this->fetch();
    }
    

    // 限制用户
    public function limit()
    {
        if (!request()->isAjax()) {
            $this->resirect('admin/index/home');
        }
        $data=input('post.');
        if (!is_array($data['id'])) {
            if (!$this->model->editStatus(intval($data['id']))) {
                return json(['errno'=>1,'msg'=>'用户限制时发生错误']);
            }
                return json(['errno'=>0,'msg'=>'用户限制成功']);
        }
            $fail=0;
        foreach ($data['id'] as $value) {
            if (!$this->model->editStatus(intval($value))) {
                $fail++;
            }
        }
        if (0===$fail) {
            return json(['errno'=>0,'msg'=>'用户限制成功']);
        }
        return json(['errno'=>1,'msg'=>'用户限制时发生错误']);
    }
}
